
const state = {
	sidebar: {
		opened: localStorage.getItem('sidebarStatus') ? !!+localStorage.getItem('sidebarStatus') : true,
		withoutAnimation: false
	},
	device: 'desktop' ,//默认为pc宽屏，会动态获取的
	size:localStorage.getItem('size') || 'medium',//设置全局大小【如按钮、表格等】
	fontFamily:localStorage.getItem('fontFamily')||'font-family-2',//设置全局字体库，默认系统库
	menuMode:localStorage.getItem('menuMode')||'vertical',//侧边菜单默认vertical纵向布局horizontal为横向布局
	themeColor:localStorage.getItem('themeColor')||'Default',//主题颜色默认Default，可选值【Default、Green、】【默认、绿色】
	themeBtColor:localStorage.getItem('themeBtColor')||'#409EFF',//按钮主题颜色
}

const mutations = {
	TOGGLE_SIDEBAR: state => {
		state.sidebar.opened = !state.sidebar.opened
		state.sidebar.withoutAnimation = false
		console.log(localStorage.getItem('sidebarStatus'));
		if (state.sidebar.opened) {
			localStorage.setItem('sidebarStatus', 1)
		} else {
			localStorage.setItem('sidebarStatus', 0)
		}
	},
	CLOSE_SIDEBAR: (state, withoutAnimation) => {
		localStorage.setItem('sidebarStatus', 0)
		state.sidebar.opened = false
		state.sidebar.withoutAnimation = withoutAnimation
	},
	TOGGLE_DEVICE: (state, device) => {
		state.device = device
	},
	SET_SIZE: (state, size) => {
	  state.size = size
	  localStorage.setItem('size', size)
	},
	SET_FONT_FAMILY:(state, fontFamily)=>{
		state.fontFamily = fontFamily
		localStorage.setItem('fontFamily', fontFamily)
	},
	SET_MENU_MODE:(state, menuMode)=>{
		state.menuMode = menuMode
		localStorage.setItem('menuMode', menuMode)
	},
	SET_THEME_COLOR:(state, themeColor)=>{
		state.themeColor = themeColor
		localStorage.setItem('themeColor', themeColor)
	},
	SET_THEME_BT_COLOR:(state, themeBtColor)=>{
		state.themeBtColor = themeBtColor
		localStorage.setItem('themeBtColor', themeBtColor)
	}
}

const actions = {
	//切换侧边栏
	toggleSideBar({commit}) {
		commit('TOGGLE_SIDEBAR')
	},
	//关闭动画
	closeSideBar({commit}, {withoutAnimation}) {
		commit('CLOSE_SIDEBAR', withoutAnimation)
	},
	//切换设备屏幕大小
	toggleDevice({commit}, device) {
		commit('TOGGLE_DEVICE', device)
	},
	//设置全局大小【如按钮、表格等】
	setSize({commit},size){
		commit('SET_SIZE',size)
	},
	//设置全局字体库
	setFontFamily({commit},fontFamily){
		commit('SET_FONT_FAMILY',fontFamily)
	},
	//设置全局布局默认为纵向
	setMenuMode({commit},menuMode){
		commit('SET_MENU_MODE',menuMode)
	},
	//设置主题颜色
	setThemeColor({commit},themeColor){
		commit('SET_THEME_COLOR',themeColor)
	},
	//设置主题按钮颜色
	setThemeBtColor({commit},themeBtColor){
		commit('SET_THEME_BT_COLOR',themeBtColor)
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
